import React from "react"
import styles from "./Head.module.scss"
import { useHistory } from 'react-router-dom'
import useStore from "../../context/store"
const Head: React.FC = () => {
    let history = useHistory()
    let { head } = useStore()
    function goBack() {
        history.goBack()
    }
    function changeFile(e) {
        let data = e.target.files[0]
        let reader = new FileReader()
        reader.readAsDataURL(data)
        reader.onload =async function (result) {
            let str:string=this.result as string
            console.log(str)
            let obj={
                mid:'fa291cbd52aa40d2b47ba96c8ec59c99',
                avatar:str
            }
            head.setHead(obj)
        }
    }
    return <div className={styles.wrap}>
        <header className='header'>
            <div className={styles.push} onClick={goBack}>
                {'<'}
            </div>
            <div className={styles.text} >
                修改头像
            </div>
        </header>
        <div>
            <input type="file" onChange={changeFile} />
        </div>
    </div>
}
export default Head